package org.example.biz;

import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

@Component
@Data
public class HelloBiz {

    private String name;

    HelloBiz(){

    }

    public HelloBiz(String name) {
        this.name = name;
        System.out.println("helloBiz =1 " + helloBiz);
        System.out.println("HelloBiz 构造函数");
    }

    public void hello(){
        System.out.println("hello " + name);
    }

    public void test(){
        System.out.println("test " + name);
    }

    public int opAdd(int a, int b){
        return a + b;
    }

    public int opSub(int a, int b){
        return a / b;
    }

    // 从容器中注入的对象
//    @Autowired
    HelloBiz helloBiz;

    @PostConstruct
    public void init(){
        // 初始化该对象, 同时还要访问 IOC 容器中其它对对象
        System.out.println("helloBiz =2 " + helloBiz);
        System.out.println("HelloBiz init  " + name);
    }

    @PreDestroy
    public void destroy(){
        System.out.println("HelloBiz destroy");
    }
}
